﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Panel.Master" Inherits="System.Web.Mvc.ViewPage<IList<Prodma.DataAccess.Models.ViewModels.MenuVm>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	<%=System.Configuration.ConfigurationManager.AppSettings["pageTitle"] %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <div class="listHeader">
        <img src="../../Images/ListImages/menulist.png" alt="" class="listHeaderIco" />
        <div class="listHeaderText">Menü Yöneticisi</div>
        
        <div class="listHeaderMenuBox">
            <% Html.RenderPartial("/views/shared/userControls/navigation.ascx",
                   Prodma.DataAccess.Authorization.Authorization.GetNavigation(
                    "menu", 
                    7,
                    new List<string>() { "location" }, 
                    new List<string>() { Request.QueryString["location"] }));%>
        </div>
    </div>
    
    <div class="listFindBar">
    
    </div>
    
    <div class="listTitleContainer">
        <div class="listTitleCenter-50">#</div>
        <div class="listTitleCenter-50"><input type="checkbox" id="chk" name="chk" /></div>
        <div class="listTitleLeft-200">Menü</div>
        <div class="listTitleCenter-150">Sıra</div>
        <div class="listTitleCenter-150">Durum</div>
        <div class="listTitleCenter-50">ID</div>
    </div>
    
    <div class="listRowContainer">
    <!-- Set ParentMenu & SubMenu -->
    <% List<Prodma.DataAccess.Models.ViewModels.MenuVm> parentMenuItems = new List<Prodma.DataAccess.Models.ViewModels.MenuVm>(); %>
    <% List<Prodma.DataAccess.Models.ViewModels.MenuVm> subMenuItems = new List<Prodma.DataAccess.Models.ViewModels.MenuVm>(); %>
    <% for (int i = 0; i < ViewData.Model.Count; i++) %>
    <% { %>
         <% for (int j = 0; j < ViewData.Model.Count; j++)%>
         <% { %>
              <% if (ViewData.Model[i].Id == ViewData.Model[j].Parent.Id) %>
              <% { %>
                   <% ViewData.Model[i].SubItemCount++; %>
              <% } %>
         <% } %>
         
         <% if (ViewData.Model[i].Parent.Id == 0) %>
         <% { %>
              <% parentMenuItems.Add(ViewData.Model[i]); %>
         <% } %>
         <% else %>
         <% { %>
              <% subMenuItems.Add(ViewData.Model[i]); %>
         <% } %>
    <% } %>
    <!--***************************-->
    <% int counter = 0; %>
    <% foreach (Prodma.DataAccess.Models.ViewModels.MenuVm parent in parentMenuItems) %>
    <% { %>
         <% counter++; %>
         <!-- List of Parent Menu -->
         <div class="listRow1">
              <div class="listColumnCenter-50"><%=counter %></div>                      
              <div class="listColumnCenter-50"><input type="checkbox" id='chk<%=parent.Id %>' name="chkSelect" /></div>
              <div class="listColumnLeft-200">
                <a href='/menu/edit/?id=<%=parent.Id %>&location=<%=parent.Location.Id %>' class="listSelectItemBold">
                    <%=parent.Name%>
                </a>
              </div>
              <div class="listColumnCenter-150">
                    <% if (parent.Order.OrderNo != 1) %>
                    <% { %>
                           <a href='/menu/orderUp/?id=<%=parent.Id %>&orderNo=<%=parent.Order.OrderNo %>&location=<%=parent.Location.Id %>&parentId=<%=parent.Parent.Id %>'><img src="../../Images/ListImages/orderup.png" border="0" alt="" /></a>
                    <% } %>
                    <% else %>
                    <% { %>
                           <img src="../../Images/ListImages/blankorder.png" alt="" />
                    <% } %>
                    <% if (parent.Order.OrderNo != parentMenuItems.Count) %>
                    <% { %>
                           <a href='/menu/orderDown/?id=<%=parent.Id %>&orderNo=<%=parent.Order.OrderNo %>&location=<%=parent.Location.Id %>&parentId=<%=parent.Parent.Id %>'><img src="../../Images/ListImages/orderdown.png" border="0" alt="" /></a>
                    <% } %>
                    <% else %>
                    <% { %>
                           <img src="../../Images/ListImages/blankorder.png" alt="" />
                    <% } %>                                
                    <input type="text" id='order<%=counter %>' name="order" value='<%=parent.Order.OrderNo %>' class="listOrderInput" maxlength="5"  />
                    <a id='aSetOrder<%=counter %>' onclick='setOrder(<%=counter %>)' ><img src="../../Images/ListImages/orderok.png" border="0" alt="" /></a>
                    <input type="hidden" id='hdnSetOrder<%=counter %>' value='/menu/setOrder/?id=<%=parent.Id %>&orderNo=<%=parent.Order.OrderNo %>&location=<%=parent.Location.Id %>&parentId=<%=parent.Parent.Id %>' />
              </div>
              <div class="listColumnCenter-150"><%=parent.State.Name%></div>
              <div class="listColumnCenter-50"><%=parent.Id%></div>
          </div>
          <!-- List of Sub Menu -->
          <% foreach (Prodma.DataAccess.Models.ViewModels.MenuVm sub in subMenuItems) %>
          <% { %>
               <% if (parent.Id == sub.Parent.Id) %>
               <% { %>
                    <% counter++; %>
                    <div class="listRow1">
                      <div class="listColumnCenter-50"><%=counter %></div>                      
                      <div class="listColumnCenter-50"><input type="checkbox" id='chk<%=sub.Id %>' name="chkSelect" /></div>
                      <div class="listColumnLeft-200">
                        -----<a href='/menu/edit/?id=<%=sub.Id %>&location=<%=sub.Location.Id %>' class="listSelectItemNormal">
                            <%=sub.Name%>
                        </a>
                      </div>
                      <div class="listColumnCenter-150">
                        <% if (sub.Order.OrderNo != 1) %>
                            <% { %>
                                   <a href='/menu/orderUp/?id=<%=sub.Id %>&orderNo=<%=sub.Order.OrderNo %>&location=<%=sub.Location.Id %>&parentId=<%=sub.Parent.Id %>'><img src="../../Images/ListImages/orderup.png" border="0" alt="" /></a>
                            <% } %>
                            <% else %>
                            <% { %>
                                   <img src="../../Images/ListImages/blankorder.png" alt="" />
                            <% } %>
                            <% if (sub.Order.OrderNo != parent.SubItemCount) %>
                            <% { %>
                                   <a href='/menu/orderDown/?id=<%=sub.Id %>&orderNo=<%=sub.Order.OrderNo %>&location=<%=sub.Location.Id %>&parentId=<%=sub.Parent.Id %>'><img src="../../Images/ListImages/orderdown.png" border="0" alt="" /></a>
                            <% } %>
                            <% else %>
                            <% { %>
                                   <img src="../../Images/ListImages/blankorder.png" alt="" />
                            <% } %>                                
                            <input type="text" id='order<%=counter %>' name="order" value='<%=sub.Order.OrderNo %>' class="listOrderInput" maxlength="5"  />
                            <a id='aSetOrder<%=counter %>' onclick='setOrder(<%=counter %>)' ><img src="../../Images/ListImages/orderok.png" border="0" alt="" /></a>
                            <input type="hidden" id='hdnSetOrder<%=counter %>' value='/menu/setOrder/?id=<%=sub.Id %>&orderNo=<%=sub.Order.OrderNo %>&location=<%=sub.Location.Id %>&parentId=<%=sub.Parent.Id %>' />
                      </div>
                      <div class="listColumnCenter-150"><%=sub.State.Name%></div>
                      <div class="listColumnCenter-50"><%=sub.Id%></div>
                  </div>
               <% } %>
          <% } %>
    <% } %>
    </div>

    <script type="text/javascript">
        $(function() {
            $('#chk').click(function() {
                $("input[type='checkbox']").attr('checked', $('#chk').is(':checked'));
            });
        });

        function deleteRow() {
            var result = confirm('Seçili kayıt(lar) silinsin mi?');
            if (!result)
                return false;

            var idList = new Array();

            $("input[@name=chkSelect][checked]").each(
              function() {
                  if (this.id != 'chk') {
                      idList.push(this.id);
                  }
              }
            );

            if (idList.length == 0)
                return false;

            window.location.replace('/menu/delete/?idList=' + idList);
        }

        function editRow() {
            $("input[@name=chkSelect][checked]").each(
              function() {
                  if (this.id != 'chk') {
                      window.location.replace('/menu/edit/?id=' + this.id.substring(3, this.id.length));
                  }
              }
            );
          }

          function setOrder(counter) {
              var newOrderNo = $('#order' + counter).val();
              if (newOrderNo == '' || newOrderNo <= 0) {
                  alert('Yeni sıra numarası pozitif bir sayı olmalıdır !');
                  $('#order' + counter).focus();
                  return false;
              }
              else {
                  var txtOrderNo = $('#order' + counter).val();
                  window.location.replace($('#hdnSetOrder' + counter).val() + "&setOrderNo=" + $('#order' + counter).val());
              }
          }
    </script>

</asp:Content>
